package com.sxjh.controller.cb;

import com.sxjh.common.BaseController;
import com.sxjh.config.Authorization;
import com.sxjh.common.Result;
import com.sxjh.entity.param.*;
import com.sxjh.entity.result.Finance3CbResult;
import com.sxjh.entity.result.Finance3HgcgwlResult;
import com.sxjh.entity.result.Finance3HgylcgrbbResult;
import com.sxjh.entity.result.FinanceList7Result;
import com.sxjh.service.FinanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/chemical-big")
@Api(tags = "化工原料")
public class Finance3Controller extends BaseController {

  @Autowired
  private FinanceService financeService;

  @GetMapping("/jy")
  @ApiOperation("煤焦油")
  @Authorization("cb.chemical-big.jy")
  Result<List<FinanceList7Result>> list(@Validated Finance3CbParam param) {
    return ok(financeService.list9(param));
  }

  @GetMapping("/jy-cd")
  @ApiOperation("焦油拆单")
  @Authorization("cb.chemical-big.jy-cd")
  Result<Void> jyCd(@Validated Finance3CbCd param) {
    try {
      financeService.tear(param);
    } catch (RuntimeException e) {
      return err(e.getMessage());
    }
    return ok();
  }

  @GetMapping("/cb")
  @ApiOperation("粗笨")
  @Authorization("cb.chemical-big.cb")
  Result<List<Finance3CbResult>> cb(@Validated Finance3CbParam param) {
    return ok(financeService.list10(param));
  }

  @GetMapping("/cb-cd")
  @ApiOperation("粗笨拆单")
  @Authorization("cb.chemical-big.cb-cd")
  Result<Void> cbCd(@Validated Finance3CbCd param) {
    try {
      financeService.tear(param);
    } catch (RuntimeException e) {
      return Result.err(e.getMessage());
    }
    return Result.ok();
  }

  @GetMapping("/hgylcgrbb")
  @ApiOperation("化工原料采购日报表")
//  @Authorization("cb.chemical-big.cb-cd")
  Result<List<Finance3HgylcgrbbResult>> hgylcgrbb(@Validated Finance10Param param) {
    return ok(financeService.list29(param));
  }
  @GetMapping("/hgyljcyhzb")
  @ApiOperation("化工原料进厂月汇总表")
//  @Authorization("cb.chemical-big.cb-cd")
  Result<Map<String,Object>> hgyljcyhzb(@Validated Finance10JcParam param) {
    return ok(financeService.list30(param));
  }

  @GetMapping("/hgcgwl")
  @ApiOperation("化工采购物料")
//  @Authorization("cb.chemical-big.cb-cd")
  Result<List<Finance3HgcgwlResult>> hgcgwl() {
    return ok(financeService.list31());
  }
}